import java.util.*;
public class Practice1 {
    //https://www.nowcoder.com/questionTerminal/99fa7be28d5f4a9d9aa3c98a6a5b559a
    static Set<Integer> list;
    public static void main(String[] args) {
        list = new HashSet<>();
        boolean[] arr = new boolean[100];
        for(int i = 2;i < 100;i++){
            if(!arr[i]){
                list.add(i);
                for(int j = i * i;j < 100;j += i){
                    arr[j] = true;
                }
            }
        }
        int count = 0;
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        for (int i = a; i <= b; i++) {
            count += check(i);
        }
        System.out.println(count);
    }

    private static int check(int t) {
        int n = 0;
        int[] arr = new int[5];
        while(t != 0){
            arr[n++] = t % 10;
            t /= 10;
        }
        for(int i = 0;i < n;i++){
            for (int j = 0; j < n; j++) {
                if(i != j && arr[i] != 0){
                    if(list.contains(arr[i] * 10 + arr[j])){
                        return 1;
                    }
                }
            }
        }
        return 0;
    }


}
